package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.common.result.ResultCodeEnum;
import com.atguigu.lease.model.entity.LeaseTerm;
import com.atguigu.lease.web.admin.service.LeaseTermService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 小可乐$ on 2024/8/12$ 15:18$
 * description:租期管理
 */
@Tag(name = "租期管理")
@RestController
@RequestMapping("/admin/term")
public class LeaseTermController {
    @Autowired
    private LeaseTermService leaseTermService;
    /**
     * 保存或更新租期信息
     * */
    @Operation(summary = "保存更新租期信息")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody LeaseTerm leaseTerm){
        leaseTermService.saveOrUpdate(leaseTerm);
        return Result.ok();
    }
    /**
     * 查询全部租期列表
     * */
    @Operation(summary = "查询全部租期列表")
    @GetMapping("/list")
    public Result findAll(){
        List<LeaseTerm> list = leaseTermService.list();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }
    /**
     * 根据id删除租期
     * */
    @Operation(summary = "根据id删除租期信息")
    @DeleteMapping("deleteById")
    public Result deleteById(@RequestParam("id") Long id){
        leaseTermService.removeById(id);
        return Result.ok();
    }

}
